//
//  AddPhotoViewController.m
//  jingdongfang
//
//  Created by MTiMac02 on 2017/11/2.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "AddPhotoViewController.h"
#import "SliderViewController.h"
#import "CollectVC.h"
#import "OpenVC.h"
#import "PrivateVC.h"

@interface AddPhotoViewController ()<SliderViewControllerDelegate>{
    
    CollectVC *vc1;
    OpenVC *vc2;
    PrivateVC *vc3;
}
@property (nonatomic, strong)  SliderViewController *sliderVC;
@end

@implementation AddPhotoViewController
@synthesize sliderVC;

#pragma mark -生命周期
- (void)viewDidLoad {
        [super viewDidLoad];
//        self.title = @"添加图片到图册";
        self.title = NSLocalizedString(@"Add Pictures to Album", nil);

        if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
        {
            self.edgesForExtendedLayout = UIRectEdgeNone;
        }
    
        sliderVC = [[SliderViewController alloc] initWithFrame:CGRectMake(0, 0, KSCREENWIDTH, KSCREENHEIGHT-NavigationMagin)];
        sliderVC.slideSwitchViewDelegate = self;
        sliderVC.topScrollView.backgroundColor=[UIColor whiteColor];
        sliderVC.tabItemNormalColor = RGB(115, 115, 115);
        sliderVC.tabItemSelectedColor = [UIColor blackColor];
        [self.view addSubview:sliderVC];
        
        [sliderVC buildUI];
        [self loadModel];
        if (self.index)
        {
            [sliderVC selectIndex:self.index];
        }
    }
- (void)setIndex:(NSInteger)index {
        if (_index != index) {
            _index = index;
        }
        if (sliderVC) {
            [sliderVC selectIndex:index];
            [self loadModel];
        }
    }
- (void)loadModel
{
    [vc1 viewDidLoad];
    [vc2 viewDidLoad];
    [vc3 viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(coverWindowClick) name:@"click" object:nil];
    
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"click" object:nil];
}
//    - (void)upDataSucc:(NSNotification *)not
//    {
//        BOOL isPublic = [not.object boolValue];
//        self.index = isPublic ? 0 : 1;
//    }
#pragma mark - SliderViewControllerDelegate
    
    - (NSUInteger)numberOfTab:(SliderViewController *)view {
        return 3;
    }
    
    - (UIViewController *)slideSwitchView:(SliderViewController *)view viewOfTab:(NSUInteger)number {

        if (number == 0)
        {
            vc1 = [[CollectVC alloc] init];
//            vc1.title = @"收藏馆";
            vc1.title = NSLocalizedString(@"Collection Library", nil);
            vc1.aid=self.albumId;
            vc1.nav = self.navigationController;
            return vc1;
        }
        else if (number == 1)
        {
            vc2 = [[OpenVC alloc] init];
//            vc2.title = @"公开馆";
            vc2.title = NSLocalizedString(@"Public", nil);
            vc2.aid=self.albumId;
            vc2.nav = self.navigationController;
            return vc2;
        }
        else if (number == 2)
        {
            vc3 = [[PrivateVC alloc] init];
//            vc3.title = @"私密馆";
            vc3.title = NSLocalizedString(@"Private", nil);
            vc3.aid=self.albumId;
            vc3.nav = self.navigationController;
            return vc3;
        }

        return nil;
    }

    - (void)coverWindowClick
    {
        
        if (sliderVC.userSelectedChannelID == 100)
        {
            [vc1 scrollToTOP];
            
        }
        else if (sliderVC.userSelectedChannelID == 101)
        {
            [vc2 scrollToTOP];
        }
        else if (sliderVC.userSelectedChannelID == 102)
        {
            [vc3 scrollToTOP];
        }

    }
    - (void)dealloc
    {
        [[NSNotificationCenter defaultCenter] removeObserver:self];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    

@end
